package xyz.xpman.prisonerfitness.adapter;

import android.annotation.SuppressLint;
import android.os.Build;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import org.jetbrains.annotations.NotNull;

import xyz.xpman.prisonerfitness.R;
import xyz.xpman.prisonerfitness.entity.Mappings;
import xyz.xpman.prisonerfitness.entity.TrainingRecord;
import xyz.xpman.prisonerfitness.kit.ResKit;

@RequiresApi(api = Build.VERSION_CODES.O)
public class TrainingRecordSimpleCache implements IViewCache<TrainingRecord> {
    private final TextView SequenceView;
    private final TextView titleView;
    private final TextView trainingStandard;


    public TrainingRecordSimpleCache(
            @NotNull TextView SequenceView,
            @NotNull TextView titleView,
            @NotNull TextView trainingStandard) {

        this.SequenceView = SequenceView;
        this.titleView = titleView;
        this.trainingStandard = trainingStandard;
    }


    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


    private void setTitle(String title) {
        titleView.setText(title);
    }

    private void setSequence(String serialNum) {
        this.SequenceView.setText(serialNum);
    }


    private void setTrainingStandard(@NotNull String trainingStandard) {
        this.trainingStandard.setText(trainingStandard);
    }



    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



    @Override
    public void process(int position, @NotNull TrainingRecord item) {
        final String sequenceFmt = "%2d%s ";
        @SuppressLint("DefaultLocale")
        final String sequence = String.format(sequenceFmt, position + 1,
                ResKit.getString(R.string.sequence_number_separator));
        setSequence(sequence);


        String title = Mappings.getMovesTitle(item.getMovesId())
                + Mappings.getChapterTitle(item.getChapterId());

        if (item.isWarmUpTraining()) {
            title = title + "(" + ResKit.getString(R.string.warm_up_cn) + ")";
        }

        setTitle(title);


        //  1组 X  1次
        // 10组 X  2次
        // 10组 X 10次
        final String format = "%2d%s X %2d%s";
        @SuppressLint("DefaultLocale")
        final String trainingStandard = String.format(format,
                item.getStandardGroups(), ResKit.getString(R.string.group_cn),
                item.getStandardTimes(), ResKit.getString(R.string.times_cn));

        setTrainingStandard(trainingStandard);
    }

}
